home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 52498 / 52498.xpi / chrome / optimizegoogle.jar / content / optimizegoogle / browser.xul < prev    next >
Extensible Markup Language  |  2009-11-23  |  20KB  |  456 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE overlay SYSTEM "chrome://optimizegoogle/locale/browser.dtd">
  4.  
  5. <overlay id="optimizegoogle-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  6.  
  7. <stringbundleset id="stringbundleset">
  8.     <stringbundle id="web_texts" src="chrome://optimizegoogle/locale/web_texts.properties"/>
  9. </stringbundleset>
  10.  
  11. <script type="application/x-javascript">
  12. <![CDATA[
  13. function do_optimizegoogle(e) {
  14.  
  15.     var href = e.originalTarget.location.href;
  16.     var text = "";
  17.     
  18.     // Google
  19.     if (!(/\.(js|css|xml|rss|pdf)$/.test(href)) && !(/complete\/search/.test(href)) && ( /^http[s]?:\/\/.*?\.(google|googleproxy|youtube)\.[a-z\.]+\//.test(href) || (/^http:\/\/(64\.233\.161\.99|64\.233\.161\.104|64\.233\.161\.105|64\.233\.161\.147|64\.233\.167\.99|64\.233\.167\.104|64\.233\.167\.147|64\.233\.171\.99|64\.233\.171\.104|64\.233\.171\.105|64\.233\.171\.147|64\.233\.179\.99|64\.233\.179\.99|64\.233\.183\.99|64\.233\.183\.104|64\.233\.185\.99|64\.233\.185\.104|64\.233\.187\.99|64\.233\.187\.104|64\.233\.189\.104|66\.102\.7\.104|66\.102\.7\.105|66\.102\.7\.147|66\.102\.9\.104|66\.102\.11\.104|216\.239\.37\.104|216\.239\.37\.105|216\.239\.37\.147|216\.239\.39\.104|216\.239\.53\.104|216\.239\.57\.98|216\.239\.57\.104|216\.239\.57\.105|216\.239\.57\.147|216\.239\.59\.104|216\.239\.59\.105|216\.239\.63\.104|66\.249\.81\.99)\//.test(href)) )) {
  20.  
  21.         // Load texts
  22.         var stringbundle = document.getElementById("web_texts");
  23.         // bad solution - but stringbundle.strings was introduced in Mozilla 1.8!
  24.         var textarr = new Object();
  25.         textarr["try_search"] = stringbundle.getString("try_search");
  26.         textarr["find_reviews"] = stringbundle.getString("find_reviews");
  27.         textarr["find_news"] = stringbundle.getString("find_news");
  28.         textarr["find_forecasts"] = stringbundle.getString("find_forecasts");
  29.         textarr["find_products"] = stringbundle.getString("find_products");
  30.         textarr["filter"] = stringbundle.getString("filter");
  31.         textarr["filter_match"] = stringbundle.getString("filter_match");
  32.         textarr["origin_image"] = stringbundle.getString("origin_image");
  33.         textarr["origin_page"] = stringbundle.getString("origin_page");
  34.         textarr["history"] = stringbundle.getString("history");
  35.         textarr["save"] = stringbundle.getString("save");
  36.  
  37.         //var enum = stringbundle.strings;
  38.         //while (enum.hasMoreElements()) {
  39.             //var prop = enum.getNext();
  40.             //prop = prop.QueryInterface(Components.interfaces.nsIPropertyElement);
  41.             //textarr[prop.key] = prop.value;
  42.         //}
  43.         
  44.         // Load filters
  45.         var filterlist = cg_getPref("string","extensions.optimizegoogle.misc.filterlist","");
  46.         filterlist = filterlist.replace(/\s/g, " ");
  47.         filterlist = filterlist.replace(/'/g, "\\'");
  48.         //var filterlist = '';
  49.         
  50.         //Used when streaming new results - script not needed for those pages.
  51.         var disable = href.match(/#disable-userscript$/);
  52.         
  53.         text += "var textarr = new Object("+textarr.toSource()+");";
  54.         
  55.         text += "OptimizeGoogle.showAdPreviews();\n";
  56.         
  57.         // Google web search
  58.         if ( href.match(/^http:\/\/[^\/]+\/(search|#hl|cse|webhp|custom|unclesam|linux|bsd|mac|microsoft|intl)/)) {
  59.             
  60.             // only if necessarry
  61.             if (!disable) {
  62.                 if (cg_getPref("bool","extensions.optimizegoogle.web.remove-ads",false)) {
  63.                     text += "OptimizeGoogle.removeSponsoredLinksById(new Array('tpa1','tpa2','tpa3','spa1','mbEnd','tads'));\n";
  64.                     text += "OptimizeGoogle.removeSponsoredLinksRight();\n";
  65.                     text += "OptimizeGoogle.removeInternalAds();\n";
  66.                 }
  67.                 if (cg_getPref("bool","extensions.optimizegoogle.web.search-links",true)) {
  68.                     text += "OptimizeGoogle.addOtherWebSearches('"+cg_createUrls('websearch')+"');\n";
  69.                 }
  70.             }
  71.             if (cg_getPref("bool","extensions.optimizegoogle.web.removeclicktrack",false)) {
  72.                 text += "OptimizeGoogle.removeUrlClickTrack();\n";
  73.             }
  74.             if (cg_getPref("bool","extensions.optimizegoogle.web.filter",true)) {
  75.                 text += "OptimizeGoogle.filterWebsitesFromSearch('"+filterlist+"','"+cg_getPref("string","extensions.optimizegoogle.misc.filtercolor", "#aaaaaa")+"');\n";
  76.             }
  77.             if (cg_getPref("bool","extensions.optimizegoogle.web.save",false)) {
  78.                 text += "OptimizeGoogle.addBookmarks('"+cg_getPref("string","extensions.optimizegoogle.web.save-handler", "bookmark")+"');\n";
  79.             }
  80.             if (cg_getPref("bool","extensions.optimizegoogle.web.counter",false)) {
  81.                 text += "OptimizeGoogle.addCountSearchResults();\n";
  82.             }
  83.             if (cg_getPref("bool","extensions.optimizegoogle.web.history",false)) {
  84.                 text += "OptimizeGoogle.addWayBackMachine();\n";
  85.             }
  86.             if (cg_getPref("bool","extensions.optimizegoogle.web.favicons",false)) {
  87.                 text += "OptimizeGoogle.addFavicons();\n";
  88.             }
  89.             if (cg_getPref("bool","extensions.optimizegoogle.web.searchwiki",false)) {
  90.                 text += "OptimizeGoogle.removeSearchWiki();\n";
  91.             }
  92.             if ("en-US" == 'zh-CN') {
  93.                 text += "OptimizeGoogle.bypassChineseFirewall();\n";
  94.             }
  95.         }
  96.         // only if necessarry
  97.         if (!disable) {
  98.             // Google web search
  99.             if (href.match(/^http:\/\/[^\/]+\/(search|#hl)/)) {
  100.                 if (cg_getPref("bool","extensions.optimizegoogle.web.auto-page",false)) {
  101.                     text += "OptimizeGoogle.addAutoPager();\n";
  102.                 }
  103.             }
  104.             if ((href.match(/^http:\/\/[^\/]+\/$/) || href.match(/^http:\/\/[^\/]+\/(search|#hl|custom|firefox|webhp|unclesam|linux|bsd|mac|microsoft|ig)/))) {
  105.                 if (cg_getPref("bool","extensions.optimizegoogle.web.focus",false)) {
  106.                     text += "OptimizeGoogle.addSearchFieldFocus();\n";
  107.                 }
  108.                 if (cg_getPref("bool","extensions.optimizegoogle.web.suggest",true)) {
  109.                     text += "OptimizeGoogle.addGoogleSuggest();\n";
  110.                 }
  111.             }
  112.         }
  113.         
  114.         // Google image search
  115.         if (href.match(/^http:\/\/[^\/]+\/images/)) {
  116.             // only if necessarry
  117.             if (!disable) {
  118.                 if (cg_getPref("bool","extensions.optimizegoogle.images.image-links",true)) {
  119.                     text += "OptimizeGoogle.addOtherImageSearches('"+cg_createUrls('imagesearch')+"');\n";
  120.                 }
  121.                 if (cg_getPref("bool","extensions.optimizegoogle.images.auto-page",false)) {
  122.                     text += "OptimizeGoogle.addAutoPager();\n";
  123.                 }
  124.                 if (cg_getPref("bool","extensions.optimizegoogle.images.remove-ads",false)) {
  125.                     text += "OptimizeGoogle.removeSponsoredLinksImages();\n";
  126.                 }
  127.             }
  128.             if (cg_getPref("bool","extensions.optimizegoogle.images.rewrite-links",true)) {
  129.                 text += "OptimizeGoogle.pointLinksToImages();\n";
  130.             }
  131.         }
  132.         
  133.         // Google Blog search
  134.         if (href.match(/^http:\/\/[^\/]+\/blogsearch/)) {
  135.             if (cg_getPref("bool","extensions.optimizegoogle.blogs.blog-links",true)) {
  136.                 text += "OptimizeGoogle.addOtherBlogSearches('"+cg_createUrls('blogsearch')+"');\n";
  137.             }
  138.             if (cg_getPref("bool","extensions.optimizegoogle.blogs.removeclicktrack",false)) {
  139.                 text += "OptimizeGoogle.removeUrlClickTrack();\n";
  140.             }
  141.         }
  142.         
  143.         // Google Groups
  144.         if (href.match(/^http:\/\/[^\/]+\/group\//)) {
  145.             if (cg_getPref("bool","extensions.optimizegoogle.groups.remove-ads",false)) {
  146.                 text += "OptimizeGoogle.removeSponsoredLinksFrame();\n";
  147.             }
  148.         }
  149.         if (href.match(/^http:\/\/[^\/]+\/groups/)) {
  150.             if (cg_getPref("bool","extensions.optimizegoogle.groups.remove-ads",false)) {
  151.                 text += "OptimizeGoogle.removeSponsoredLinksRight();\n";
  152.             }
  153.         }
  154.         
  155.         // Google News
  156.         if (href.match(/^http:\/\/[^\/]+\/news/)) {
  157.             if (cg_getPref("bool","extensions.optimizegoogle.news.news-links",true)) {
  158.                 text += "OptimizeGoogle.addOtherNewsSearches('"+cg_createUrls('newssearch')+"');\n";
  159.             }
  160.         }
  161.         if (href.match(/^http:\/\/[^\/]+\/(news|nwshp)/) || href.match(/^http:\/\/news\.google\./)) {
  162.             if (cg_getPref("bool","extensions.optimizegoogle.news.filter",false)) {
  163.                 text += "OptimizeGoogle.filterWebsitesFromNews('"+filterlist+"','"+cg_getPref("string","extensions.optimizegoogle.misc.filtercolor", "#aaaaaa")+"');\n";
  164.             }
  165.             if (cg_getPref("bool","extensions.optimizegoogle.news.removeclicktrack",false)) {
  166.                 text += "OptimizeGoogle.removeUrlClickTrack();\n";
  167.             }
  168.         }
  169.         
  170.         // Google Shopping
  171.         if (href.match(/^http:\/\/[^\/]+\/(froogle|products)/)) {
  172.             if (cg_getPref("bool","extensions.optimizegoogle.froogle.remove-ads",false)) {
  173.                 text += "OptimizeGoogle.removeSponsoredLinksProducts();\n";
  174.             }
  175.             if (cg_getPref("bool","extensions.optimizegoogle.froogle.products-links",true)) {
  176.                 text += "OptimizeGoogle.addOtherProductSearches('"+cg_createUrls('productsearch')+"');\n";
  177.             }
  178.         }
  179.         
  180.         // Reader
  181.         if (href.match(/^http:\/\/[^\/]+\/reader/) && !href.match(/^http:\/\/[^\/]+\/reader\/(api|perf)/)) {
  182.             if (cg_getPref("bool","extensions.optimizegoogle.reader.secure",false)) {
  183.                 text += "OptimizeGoogle.secureGoogle();\n";
  184.             }
  185.         }
  186.         
  187.         // History
  188.         if (href.match(/^http:\/\/[^\/]+\/(history|bookmarks)/)) {
  189.             if (cg_getPref("bool","extensions.optimizegoogle.history.secure",false)) {
  190.                 text += "OptimizeGoogle.secureGoogle();\n";
  191.             }
  192.         }
  193.  
  194.         // Google Answers
  195.         if (href.match(/^http:\/\/[^\/]+\/answers/)) {
  196.             if (cg_getPref("bool","extensions.optimizegoogle.answers.remove-ads",false)) {
  197.                 text += "OptimizeGoogle.removeSponsoredLinksFrame();\n";
  198.             }
  199.         }
  200.         
  201.         // Google Book Search
  202.         if (href.match(/^http:\/\/[^\/]+\/(print|books)/)) {
  203.             if (cg_getPref("bool","extensions.optimizegoogle.print.remove-ads",false)) {
  204.                 text += "OptimizeGoogle.removeSponsoredLinksRight();\n";
  205.                 text += "OptimizeGoogle.removeSponsoredLinksPrint();\n";
  206.                 text += "OptimizeGoogle.removeSponsoredLinksById(new Array('buy','buy_content'));\n";
  207.             }
  208.             if (cg_getPref("bool","extensions.optimizegoogle.print.restore-menu",true)) {
  209.                 text += "OptimizeGoogle.restoreGooglePrint();\n";
  210.             }
  211.             if (cg_getPref("bool","extensions.optimizegoogle.print.book-links",true)) {
  212.                 text += "OptimizeGoogle.addOtherBookReviews('"+cg_createUrls('booksearch')+"');\n";
  213.             }
  214.         }
  215.         
  216.         // Google Calendar
  217.         if (href.match(/^http:\/\/[^\/]+\/calendar/)) {
  218.             if (cg_getPref("bool","extensions.optimizegoogle.calendar.secure",false)) {
  219.                 text += "OptimizeGoogle.secureGoogle();\n";
  220.             }
  221.         }
  222.         
  223.         // Google Video Search
  224.         if (href.match(/^http:\/\/[^\/]+\/videosearch/)) {
  225.             if (cg_getPref("bool","extensions.optimizegoogle.video.video-links",true)) {
  226.                 text += "OptimizeGoogle.addOtherVideoSearches('"+cg_createUrls('videosearch')+"');\n";
  227.             }
  228.         }
  229.  
  230.         // Gmail
  231.         if (href.match(/^http[s]?:\/\/g?mail\.google\.[a-z\.]+\/(g?mail|hosted|a\/)/)) {
  232.             if (cg_getPref("bool","extensions.optimizegoogle.gmail.secure",true)) {
  233.                 text += "OptimizeGoogle.secureGoogle();\n";
  234.             }
  235.             if (cg_getPref("bool","extensions.optimizegoogle.gmail.remove-ads",false)) {
  236.                 // Gmail 1.0
  237.                 text += "OptimizeGoogle.removeSponsoredLinksByIdGmail(new Array('ra','rc','rp','rb'));\n";
  238.                 // Gmail 2.0
  239.                 text += "OptimizeGoogle.removeSponsoredLinksGmail();\n";
  240.             }
  241.             if (cg_getPref("bool","extensions.optimizegoogle.gmail.hidespam",false)) {
  242.                 text += "OptimizeGoogle.hideGmailSpam('"+stringbundle.getString("gmail-spam")+"');\n";
  243.             }
  244.             if (cg_getPref("bool","extensions.optimizegoogle.gmail.monospace",false)) {
  245.                 text += "OptimizeGoogle.useMonoSpaceFont();\n";
  246.             }
  247.             if (cg_getPref("bool","extensions.optimizegoogle.gmail.hidechat",false)) {
  248.                 // Gmail 1.0
  249.                 text += "OptimizeGoogle.hideID('nb_2');\n";
  250.                 // Gmail 2.0
  251.                 text += "OptimizeGoogle.hideClass('a3hTGd');\n";
  252.             }
  253.             if (cg_getPref("bool","extensions.optimizegoogle.gmail.hideinvite",false)) {
  254.                 text += "OptimizeGoogle.hideID('nb_1');\n";
  255.                 text += "OptimizeGoogle.hideID('ip');\n";
  256.                 // Gmail 2.0
  257.                 text += "OptimizeGoogle.hideClass('I94Sdc');\n";
  258.             }
  259.         }
  260.         
  261.         // Google Maps
  262.         if (href.match(/^http:\/\/[^\/]+\/(local|maphp)/) || href.match(/^http:\/\/(local|maps)\.google\.[a-z\.]+\//)) {
  263.             if (cg_getPref("bool","extensions.optimizegoogle.local.remove-ads",false)) {
  264.                 text += "OptimizeGoogle.removeSponsoredLinksLocal();\n";
  265.             }
  266.         }
  267.         
  268.         // Docs & Spreadsheets
  269.         if (href.match(/^http:\/\/(docs|spreadsheets)\.google\.[a-z\.]+\//)) {
  270.             if (cg_getPref("bool","extensions.optimizegoogle.docs.secure",false)) {
  271.                 text += "OptimizeGoogle.secureGoogle();\n";
  272.             }
  273.         }
  274.         
  275.         // Cookies
  276.         if (href.match(/^http:\/\/[^\/]+\/(search|#hl)/)) {
  277.             if (cg_getPref("bool","extensions.optimizegoogle.misc.anonymizeUID",false)) {
  278.                 text += "OptimizeGoogle.anonymizeGoogleUID();\n";
  279.             }
  280.         }
  281.         if (href.match(/google\.[a-z\.]+\//)) {
  282.             if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableDefaultPreferences",false)) {
  283.                 text += "OptimizeGoogle.defaultPreferences(";
  284.                 if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableSafeSearch",false)) {
  285.                     text += "'" + cg_getPref("string","extensions.optimizegoogle.cookies.SafeSearch","") + "',";
  286.                 } else { text += "'',";    }
  287.                 if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableSearchLanguage",false)) {
  288.                     if (cg_getPref("string","extensions.optimizegoogle.cookies.searchAnyOrSelected","any")=="any") {
  289.                         text += "'empty',";
  290.                     } else {
  291.                         text += "'" + cg_getPref("string","extensions.optimizegoogle.cookies.searchLanguage","") + "',";
  292.                     }
  293.                 } else { text += "'',";    }
  294.                 if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableInterfaceLanguage",false)) {
  295.                     text += "'" + cg_getPref("string","extensions.optimizegoogle.cookies.interfaceLanguage","") + "',";
  296.                 } else { text += "'',";    }
  297.                 if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableResultsPerPage",false)) {
  298.                     text += "'" + cg_getPref("string","extensions.optimizegoogle.cookies.ResultsPerPage","") + "',";
  299.                 } else { text += "'',";    }
  300.                 if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableResultsWindow",false)) {
  301.                     text += "'" + (cg_getPref("bool","extensions.optimizegoogle.cookies.OpenSearchResultsInNewWindow",false)?"1":"empty") + "',";
  302.                 } else { text += "'',";    }
  303.                 if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableSuggest",false)) {
  304.                     text += "'" + (cg_getPref("bool","extensions.optimizegoogle.cookies.suggest",false)?"1":"empty") + "'";
  305.                 } else { text += "''";    }
  306.                 text += ");\n";
  307.             }
  308.         }
  309.         
  310.         // YouTube
  311.         if (href.match(/youtube\.[a-z\.]+\//)) {
  312.             if (cg_getPref("bool","extensions.optimizegoogle.youtube.remove-ads",false)) {
  313.                 text += "OptimizeGoogle.removeSponsoredLinksYouTube();\n";
  314.             }
  315.         }
  316.     }
  317.     // Google Cache
  318.     if (href.match(/\/(search)\?q=cache:/)) {
  319.         if (cg_getPref("bool","extensions.optimizegoogle.cache.continue",false)) {
  320.             text += "OptimizeGoogle.cacheContinue();\n";
  321.         }
  322.     }
  323.     if (!(/\.(js|css|xml|rss|pdf)$/.test(href))) {
  324.         if (cg_getPref("bool","extensions.optimizegoogle.misc.removeGoogleAnalytics",false)) {
  325.             text += "OptimizeGoogle.anonymizeGoogleAnalytics();\n";
  326.         }
  327.     }
  328.     
  329.     //Check that the originalTarget has content (ie. is not just a script page)
  330.     var hasContent = e.originalTarget.evaluate("//div", e.originalTarget, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
  331.     //Use the old insertion if possible (doesn't work with AJAX pages).
  332.     if (text.length > 0 && e.originalTarget.body && hasContent) {
  333.         var scriptElm = e.originalTarget.createElement("script");
  334.         var insert = "(function() {\n";
  335.         insert += cg_getContents("chrome://optimizegoogle/content/javascript.js") + "\n";
  336.         insert += text;
  337.         insert += "\n})();\n";
  338.         scriptElm.appendChild(e.originalTarget.createTextNode(insert));
  339.         e.originalTarget.body.appendChild(scriptElm);
  340.         e.originalTarget.body.removeChild(scriptElm);
  341.     //Try inserting based on window.content (may not be on current tab!!)
  342.     } else {
  343.         //Check that the window.content URL is actually a Google URL before inserting to window.content.document
  344.         var matchURL = /^http[s]?:\/\/.*?\.(google|googleproxy|youtube)\.[a-z\.]+\//.test(window.content.location.href);
  345.         if (text.length > 0 && window.content.document.body && matchURL) {
  346.             var scriptElm = window.content.document.createElement("script");
  347.             var insert = "(function() {\n";
  348.             insert += cg_getContents("chrome://optimizegoogle/content/javascript.js") + "\n";
  349.             insert += text;
  350.             insert += "\n})();\n";
  351.             scriptElm.appendChild(window.content.document.createTextNode(insert));
  352.             window.content.document.body.appendChild(scriptElm);
  353.             window.content.document.body.removeChild(scriptElm);
  354.         }
  355.     }
  356. }
  357. function cg_handle_click(e) {
  358.     if (cg_getPref("bool","extensions.optimizegoogle.web.filter",true) || cg_getPref("bool","extensions.optimizegoogle.news.filter",true)) {
  359.         if (e.target.nodeName.toLowerCase() == "a" && e.target.getAttribute("cg_filter") != null && e.button == 0) {
  360.             window.openDialog('chrome://optimizegoogle/content/addfilter.xul','manager','resizable,centerscreen,modal', e.target.getAttribute("cg_filter"));
  361.         }
  362.     }
  363.     if (cg_getPref("bool","extensions.optimizegoogle.web.save",true)) {
  364.         if (e.target.nodeName.toLowerCase() == "a" && e.target.getAttribute("cg_url") != null && e.button == 0) {
  365.             PlacesCommandHook.bookmarkLink(PlacesUtils.bookmarksMenuFolderId, e.target.getAttribute("cg_url"), e.target.getAttribute("cg_title"));
  366.         }
  367.     }
  368. }
  369. function cg_getContents(aURL){
  370.     var ioService=Components.classes["@mozilla.org/network/io-service;1"]
  371.         .getService(Components.interfaces.nsIIOService);
  372.     var scriptableStream=Components
  373.         .classes["@mozilla.org/scriptableinputstream;1"]
  374.         .getService(Components.interfaces.nsIScriptableInputStream);
  375.     var channel=ioService.newChannel(aURL,null,null);
  376.     var input=channel.open();
  377.     scriptableStream.init(input);
  378.     var str=scriptableStream.read(input.available());
  379.     scriptableStream.close();
  380.     input.close();
  381.     return str;
  382. }
  383. function cg_getPref(aPrefType, aPrefString, aDefaultValue){
  384.     var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  385.     try {
  386.       switch(aPrefType) {
  387.         case "bool":
  388.           return prefs.getBoolPref(aPrefString);
  389.         case "int":
  390.           return prefs.getIntPref(aPrefString);
  391.         case "localizedstring":
  392.         case "color":
  393.         case "string":
  394.         default:
  395.           return prefs.getCharPref(aPrefString);
  396.       }
  397.     }catch(e) {
  398.       return aDefaultValue;
  399.     }
  400. }
  401. function cg_openprefs() {
  402.     window.open("chrome://optimizegoogle/content/options.xul","optimizegooglemanager","chrome,dialog,centerscreen,alwaysRaised");
  403. }
  404. function cg_createUrls(type) {
  405.     var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  406.     var ds  = rdf.GetDataSourceBlocking("chrome://optimizegoogle/locale/urls.rdf");
  407.     ds  = ds.QueryInterface(Components.interfaces.nsIRDFDataSource);
  408.  
  409.     var urls      = rdf.GetResource("http://www.optimizegoogle.com/" + type);
  410.     var url       = rdf.GetResource("http://www.optimizegoogle.com/rdf/url");
  411.     var name      = rdf.GetResource("http://www.optimizegoogle.com/rdf/name");
  412.     var s = '';
  413.     var targets = ds.ArcLabelsOut(urls);
  414.     while (targets.hasMoreElements()){
  415.         var predicate = targets.getNext();
  416.         if (predicate instanceof Components.interfaces.nsIRDFResource){
  417.             var target = ds.GetTarget(urls, predicate, true);
  418.             if (target instanceof Components.interfaces.nsIRDFResource){
  419.                 var txt_url  = ds.GetTarget(target, url,  true);
  420.                 var txt_name = ds.GetTarget(target, name, true);
  421.                 if (txt_url instanceof Components.interfaces.nsIRDFLiteral && txt_name instanceof Components.interfaces.nsIRDFLiteral) {
  422.                     var u = txt_url.Value;
  423.                     s += '<a href="'+u+'">'+txt_name.Value+'</a>, ';
  424.                 }
  425.             }
  426.         }
  427.     }
  428.     if (s.length > 0) {
  429.         s = s.substring(0,s.length-2);
  430.     }
  431.     return s;
  432. }
  433.  
  434. window.addEventListener("load", function() {
  435.     var appcontent = window.document.getElementById("appcontent");
  436.     if (appcontent) {
  437.         if (!appcontent.googlecustomized) {
  438.             appcontent.googlecustomized = true;
  439.             appcontent.addEventListener("DOMContentLoaded", do_optimizegoogle, false);
  440.             appcontent.addEventListener("click", cg_handle_click, false);
  441.         }
  442.     }
  443. }, false);
  444. ]]></script>
  445.  
  446. <menupopup id="menu_ToolsPopup">
  447.     <menuitem id="optimizegoogle-options" insertafter="devToolsSeparator"/>
  448. </menupopup>
  449.  
  450. <menupopup id="taskPopup">
  451.     <menuitem id="optimizegoogle-options" insertafter="seamonkeyfoobar"/>
  452. </menupopup>
  453.  
  454. <menuitem id="optimizegoogle-options" accesskey="&cgtoolsOptions.accesskey;" label="&cgtoolsOptions.title;" oncommand="cg_openprefs();"/>
  455.  
  456. </overlay>